package org.qy.star_client;

import org.qy.star_common.enums.ExchangeType;
import org.qy.star_common.exception.MQException;
import org.qy.star_common.message.MessageProperties;

/**
 * @author yinger
 * @description TODO
 * @date 2024/3/31 18:51
 **/
public class Producer {
    public static void main(String[] args) throws InterruptedException {
        String ip1 = "127.0.0.1";
        String ip2 = "152.136.59.108";
        Channel channel = Channel.channelFactory(ip1, 7993);
        channel.configMQContext("admin", "admin", "star");
        channel.exchangeDeclare("test", ExchangeType.DIRECT, true, false);
        channel.queueDeclare("testQueue", true, false, false);
        while (true) {
            channel.publish("test", "testQueue", 2, "你好，这是一条消息".getBytes());
        }
    }

    public static void deleteVirtualHost(Channel channel, String vhName) {
        channel.configMQContext("admin", "admin", vhName);
        if (channel.virtualHostDelete()) {
            System.out.println("删除虚拟主机成功");
        } else {
            System.out.println("删除虚拟主机失败");
        }
    }

    public static void deleteExchange(Channel channel, String exchangeName) {
        if (channel.exchangeDelete(exchangeName)) {
            System.out.println("删除交换机成功");
        } else {
            System.out.println("删除交换机失败");
        }
    }

    public static void deleteQueue(Channel channel, String queueName) {
        if (channel.queueDelete(queueName)) {
            System.out.println("队列删除成功");
        } else {
            System.out.println("队列删除失败");
        }
    }
}
